﻿/**  版本信息模板在安装目录下，可自行修改。
* hars_inspectlist.cs
*
* 功 能： N/A
* 类 名： hars_inspectlist
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2020/2/22 11:28:58   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
namespace PreeRegisterDAL
{
    /// <summary>
    /// 数据访问类:hars_inspectlist
    /// </summary>
    public partial class hars_inspectlist
    {
        public hars_inspectlist()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperMySQL.GetMaxID("id", "hars_inspectlist");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from hars_inspectlist");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            return DbHelperMySQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PreeRegisterModel.hars_inspectlist model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into hars_inspectlist(");
            strSql.Append("MainID,ApplyNo,ReportTypeName,TestSample,SampleStatus,OrderNo,StandardSampleNo,SectionOffice,kdr,Name,sex,Age,MzZyNo,BedNo,hdr,cbr,jyr,kdsj,cbsj,jbsj,jysj,cjgsj,Diagnose,ReportFormat,state,createdate)");
            strSql.Append(" values (");
            strSql.Append("@MainID,@ApplyNo,@ReportTypeName,@TestSample,@SampleStatus,@OrderNo,@StandardSampleNo,@SectionOffice,@kdr,@Name,@sex,@Age,@MzZyNo,@BedNo,@hdr,@cbr,@jyr,@kdsj,@cbsj,@jbsj,@jysj,@cjgsj,@Diagnose,@ReportFormat,@state,@createdate)");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@MainID", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ApplyNo", MySqlDbType.VarChar,100),
                    new MySqlParameter("@ReportTypeName", MySqlDbType.VarChar,100),
                    new MySqlParameter("@TestSample", MySqlDbType.VarChar,100),
                    new MySqlParameter("@SampleStatus", MySqlDbType.VarChar,100),
                    new MySqlParameter("@OrderNo", MySqlDbType.VarChar,10),
                    new MySqlParameter("@StandardSampleNo", MySqlDbType.VarChar,100),
                    new MySqlParameter("@SectionOffice", MySqlDbType.VarChar,100),
                    new MySqlParameter("@kdr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@Name", MySqlDbType.VarChar,100),
                    new MySqlParameter("@sex", MySqlDbType.VarChar,5),
                    new MySqlParameter("@Age", MySqlDbType.VarChar,10),
                    new MySqlParameter("@MzZyNo", MySqlDbType.VarChar,50),
                    new MySqlParameter("@BedNo", MySqlDbType.VarChar,50),
                    new MySqlParameter("@hdr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cbr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jyr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@kdsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cbsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jbsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jysj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cjgsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@Diagnose", MySqlDbType.VarChar,100),
                    new MySqlParameter("@ReportFormat", MySqlDbType.VarChar,100),
                    new MySqlParameter("@state", MySqlDbType.Int32,11),
                    new MySqlParameter("@createdate", MySqlDbType.Timestamp)};
            parameters[0].Value = model.MainID;
            parameters[1].Value = model.ApplyNo;
            parameters[2].Value = model.ReportTypeName;
            parameters[3].Value = model.TestSample;
            parameters[4].Value = model.SampleStatus;
            parameters[5].Value = model.OrderNo;
            parameters[6].Value = model.StandardSampleNo;
            parameters[7].Value = model.SectionOffice;
            parameters[8].Value = model.kdr;
            parameters[9].Value = model.Name;
            parameters[10].Value = model.sex;
            parameters[11].Value = model.Age;
            parameters[12].Value = model.MzZyNo;
            parameters[13].Value = model.BedNo;
            parameters[14].Value = model.hdr;
            parameters[15].Value = model.cbr;
            parameters[16].Value = model.jyr;
            parameters[17].Value = model.kdsj;
            parameters[18].Value = model.cbsj;
            parameters[19].Value = model.jbsj;
            parameters[20].Value = model.jysj;
            parameters[21].Value = model.cjgsj;
            parameters[22].Value = model.Diagnose;
            parameters[23].Value = model.ReportFormat;
            parameters[24].Value = model.state;
            parameters[25].Value = model.createdate;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PreeRegisterModel.hars_inspectlist model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hars_inspectlist set ");
            strSql.Append("MainID=@MainID,");
            strSql.Append("ApplyNo=@ApplyNo,");
            strSql.Append("ReportTypeName=@ReportTypeName,");
            strSql.Append("TestSample=@TestSample,");
            strSql.Append("SampleStatus=@SampleStatus,");
            strSql.Append("OrderNo=@OrderNo,");
            strSql.Append("StandardSampleNo=@StandardSampleNo,");
            strSql.Append("SectionOffice=@SectionOffice,");
            strSql.Append("kdr=@kdr,");
            strSql.Append("Name=@Name,");
            strSql.Append("sex=@sex,");
            strSql.Append("Age=@Age,");
            strSql.Append("MzZyNo=@MzZyNo,");
            strSql.Append("BedNo=@BedNo,");
            strSql.Append("hdr=@hdr,");
            strSql.Append("cbr=@cbr,");
            strSql.Append("jyr=@jyr,");
            strSql.Append("kdsj=@kdsj,");
            strSql.Append("cbsj=@cbsj,");
            strSql.Append("jbsj=@jbsj,");
            strSql.Append("jysj=@jysj,");
            strSql.Append("cjgsj=@cjgsj,");
            strSql.Append("Diagnose=@Diagnose,");
            strSql.Append("ReportFormat=@ReportFormat,");
            strSql.Append("state=@state");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@MainID", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ApplyNo", MySqlDbType.VarChar,100),
                    new MySqlParameter("@ReportTypeName", MySqlDbType.VarChar,100),
                    new MySqlParameter("@TestSample", MySqlDbType.VarChar,100),
                    new MySqlParameter("@SampleStatus", MySqlDbType.VarChar,100),
                    new MySqlParameter("@OrderNo", MySqlDbType.VarChar,10),
                    new MySqlParameter("@StandardSampleNo", MySqlDbType.VarChar,100),
                    new MySqlParameter("@SectionOffice", MySqlDbType.VarChar,100),
                    new MySqlParameter("@kdr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@Name", MySqlDbType.VarChar,100),
                    new MySqlParameter("@sex", MySqlDbType.VarChar,5),
                    new MySqlParameter("@Age", MySqlDbType.VarChar,10),
                    new MySqlParameter("@MzZyNo", MySqlDbType.VarChar,50),
                    new MySqlParameter("@BedNo", MySqlDbType.VarChar,50),
                    new MySqlParameter("@hdr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cbr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jyr", MySqlDbType.VarChar,100),
                    new MySqlParameter("@kdsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cbsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jbsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@jysj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@cjgsj", MySqlDbType.VarChar,100),
                    new MySqlParameter("@Diagnose", MySqlDbType.VarChar,100),
                    new MySqlParameter("@ReportFormat", MySqlDbType.VarChar,100),
                    new MySqlParameter("@state", MySqlDbType.Int32,11),
                    new MySqlParameter("@id", MySqlDbType.Int32,50)};
            parameters[0].Value = model.MainID;
            parameters[1].Value = model.ApplyNo;
            parameters[2].Value = model.ReportTypeName;
            parameters[3].Value = model.TestSample;
            parameters[4].Value = model.SampleStatus;
            parameters[5].Value = model.OrderNo;
            parameters[6].Value = model.StandardSampleNo;
            parameters[7].Value = model.SectionOffice;
            parameters[8].Value = model.kdr;
            parameters[9].Value = model.Name;
            parameters[10].Value = model.sex;
            parameters[11].Value = model.Age;
            parameters[12].Value = model.MzZyNo;
            parameters[13].Value = model.BedNo;
            parameters[14].Value = model.hdr;
            parameters[15].Value = model.cbr;
            parameters[16].Value = model.jyr;
            parameters[17].Value = model.kdsj;
            parameters[18].Value = model.cbsj;
            parameters[19].Value = model.jbsj;
            parameters[20].Value = model.jysj;
            parameters[21].Value = model.cjgsj;
            parameters[22].Value = model.Diagnose;
            parameters[23].Value = model.ReportFormat;
            parameters[24].Value = model.state;
            parameters[25].Value = model.id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_inspectlist ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_inspectlist ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_inspectlist GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,MainID,ApplyNo,ReportTypeName,TestSample,SampleStatus,OrderNo,StandardSampleNo,SectionOffice,kdr,Name,sex,Age,MzZyNo,BedNo,hdr,cbr,jyr,kdsj,cbsj,jbsj,jysj,cjgsj,Diagnose,ReportFormat,state,createdate from hars_inspectlist ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            PreeRegisterModel.hars_inspectlist model = new PreeRegisterModel.hars_inspectlist();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_inspectlist DataRowToModel(DataRow row)
        {
            PreeRegisterModel.hars_inspectlist model = new PreeRegisterModel.hars_inspectlist();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["MainID"] != null)
                {
                    model.MainID = row["MainID"].ToString();
                }
                if (row["ApplyNo"] != null)
                {
                    model.ApplyNo = row["ApplyNo"].ToString();
                }
                if (row["ReportTypeName"] != null)
                {
                    model.ReportTypeName = row["ReportTypeName"].ToString();
                }
                if (row["TestSample"] != null)
                {
                    model.TestSample = row["TestSample"].ToString();
                }
                if (row["SampleStatus"] != null)
                {
                    model.SampleStatus = row["SampleStatus"].ToString();
                }
                if (row["OrderNo"] != null)
                {
                    model.OrderNo = row["OrderNo"].ToString();
                }
                if (row["StandardSampleNo"] != null)
                {
                    model.StandardSampleNo = row["StandardSampleNo"].ToString();
                }
                if (row["SectionOffice"] != null)
                {
                    model.SectionOffice = row["SectionOffice"].ToString();
                }
                if (row["kdr"] != null)
                {
                    model.kdr = row["kdr"].ToString();
                }
                if (row["Name"] != null)
                {
                    model.Name = row["Name"].ToString();
                }
                if (row["sex"] != null)
                {
                    model.sex = row["sex"].ToString();
                }
                if (row["Age"] != null)
                {
                    model.Age = row["Age"].ToString();
                }
                if (row["MzZyNo"] != null)
                {
                    model.MzZyNo = row["MzZyNo"].ToString();
                }
                if (row["BedNo"] != null)
                {
                    model.BedNo = row["BedNo"].ToString();
                }
                if (row["hdr"] != null)
                {
                    model.hdr = row["hdr"].ToString();
                }
                if (row["cbr"] != null)
                {
                    model.cbr = row["cbr"].ToString();
                }
                if (row["jyr"] != null)
                {
                    model.jyr = row["jyr"].ToString();
                }
                if (row["kdsj"] != null)
                {
                    model.kdsj = row["kdsj"].ToString();
                }
                if (row["cbsj"] != null)
                {
                    model.cbsj = row["cbsj"].ToString();
                }
                if (row["jbsj"] != null)
                {
                    model.jbsj = row["jbsj"].ToString();
                }
                if (row["jysj"] != null)
                {
                    model.jysj = row["jysj"].ToString();
                }
                if (row["cjgsj"] != null)
                {
                    model.cjgsj = row["cjgsj"].ToString();
                }
                if (row["Diagnose"] != null)
                {
                    model.Diagnose = row["Diagnose"].ToString();
                }
                if (row["ReportFormat"] != null)
                {
                    model.ReportFormat = row["ReportFormat"].ToString();
                }
                if (row["state"] != null && row["state"].ToString() != "")
                {
                    model.state = int.Parse(row["state"].ToString());
                }
                if (row["createdate"] != null && row["createdate"].ToString() != "")
                {
                    model.createdate = DateTime.Parse(row["createdate"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,MainID,ApplyNo,ReportTypeName,TestSample,SampleStatus,OrderNo,StandardSampleNo,SectionOffice,kdr,Name,sex,Age,MzZyNo,BedNo,hdr,cbr,jyr,kdsj,cbsj,jbsj,jysj,cjgsj,Diagnose,ReportFormat,state,createdate ");
            strSql.Append(" FROM hars_inspectlist ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from hars_inspectlist T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hars_inspectlist";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod


        /// <summary>
        /// 查询检验报告条目
        /// </summary>
        /// <param name="type">8:mainid 9:一维码条码</param>
        /// <param name="typevalue">类型值</param>
        /// <returns></returns>
        public DataSet GetList(int type, string typevalue)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM hars_inspectlist where 1=1 ");

            if (type == 9 && !string.IsNullOrEmpty(typevalue))
            {
                strSql.AppendFormat(" and barcode='{0}'", typevalue);
            }
            if (type == 8 && !string.IsNullOrEmpty(typevalue))
            {
                strSql.AppendFormat(" and mainid='{0}'", typevalue);
            }
            return DbHelperMySQL.Query(strSql.ToString());
        }
        #endregion  ExtensionMethod
    }
}

